<?php

class Order extends Eloquent {

	 protected $table = 'order';

	/**
	 * Condition: Unarchived Orders and Has Unarchived Items.
	 * @author AngelaMisa 02/22/2015 2:25AM
	 * @param $query
	 * @return mixed
	 */
	public function scopeActive( $query ) {
		return $query->where($this->table . '.archived', 0)
			->whereHas('orderProducts', function( $q ) {
			$q->where('archived', 0);
		});
	}

	/**
	 * Relates to Company.
	 * @author AngelaMisa 02/22/2015 2:25AM
	 * @return mixed
	 */
	public function company() {
		return $this->belongsTo('Company', 'COMPANY_id');
	}

	/**
	 * Relates to Employee.
	 * @author AngelaMisa 02/22/2015 2:25AM
	 * @return mixed
	 */
	public function employee() {
		return $this->belongsTo('Login', 'EMPLOYEE_id');
	}

	/**
	 * Retrieves Ordered Items under Order.
	 * @author AngelaMisa 02/22/2015 2:25AM
	 * @return mixed
	 */
	public function orderProducts() {
		return $this->hasMany('OrderProduct', 'ORDER_id');
	}
}